package com.farm.quartz.controller;

import com.farm.common.core.domain.AjaxResult;
import com.farm.quartz.Dao.wuDepInfoDao;
import com.farm.quartz.domain.PlantData;
import com.farm.quartz.model.wuDepInfo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/employShow")
public class DepartmentController {
    
    @Resource
    wuDepInfoDao wuDepInfoDao;

    @GetMapping("employNum")
    public AjaxResult employNum() {
        String title = "title...";
    
        PlantData plantData = new PlantData();
        plantData.setTitle(title);
        
        List<wuDepInfo> wuDepInfoList = wuDepInfoDao.findAll();
        List<String> xAxisList = new ArrayList<>();
        List<Integer> seriesList = new ArrayList<>();
        for (int i=0; i<wuDepInfoList.size(); i++) {
            xAxisList.add(wuDepInfoList.get(i).getName());
            seriesList.add(Integer.valueOf(wuDepInfoList.get(i).getCount()));
        }
    
        String[] xAxisArr = new String[xAxisList.size()];
        for (int i = 0; i < xAxisArr.length; i++) {
            xAxisArr[i] = xAxisList.get(i);
        }
        Integer[] seriesArr = new Integer[seriesList.size()];
        for (int i = 0; i < seriesArr.length; i++) {
            seriesArr[i] = seriesList.get(i);
        }
    
        plantData.setxAxis(xAxisArr);
        plantData.setSeries(seriesArr);
    
        return AjaxResult.success("success!", plantData);
    }

}
